package com.cr.web.controller.api;

import com.cr.business.domain.TbQualifiedCertInfo;
import com.cr.business.domain.dto.app.QualifiedCertListParam;
import com.cr.business.domain.dto.app.QualifiedCertPrintParam;
import com.cr.business.domain.vo.QualifiedCertDetailInfoVo;
import com.cr.business.service.ITbQualifiedCertInfoService;
import com.cr.common.core.controller.BaseController;
import com.cr.common.core.domain.AjaxResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 合格证管理相关接口
 */
@RestController
@RequestMapping("api/qualifiedCert")
public class QualifiedCertController extends BaseController {

    @Resource
    private ITbQualifiedCertInfoService tbQualifiedCertInfoService;

    /**
     * 获取合格证列表
     */
    @GetMapping("list")
    public AjaxResult data(@Valid QualifiedCertListParam param){
        return AjaxResult.success(tbQualifiedCertInfoService.appCertList(param));
    }

    /**
     * 新增合格证
     */
    @PostMapping("add")
    public AjaxResult add(@Valid TbQualifiedCertInfo info){
        return toAjax(tbQualifiedCertInfoService.addCert(info));
    }

    /**
     * 合格证详情
     * @param certId
     * @return
     */
    @GetMapping("info/{certId}")
    public AjaxResult info(@PathVariable("certId") String certId){
        QualifiedCertDetailInfoVo data = tbQualifiedCertInfoService.appGetQualifiedCertInfo(certId);
        if(data != null) {
            data.setEntityId(null);
        }
        return AjaxResult.success(data);
    }

    /**
     * 合格证打印
     */
    @PostMapping("print")
    public AjaxResult print(@RequestBody List<QualifiedCertPrintParam> params) {
        tbQualifiedCertInfoService.savePrintData(params);
        return AjaxResult.success();
    }

    /**
     * 获取首页数据
     */
    @GetMapping("indexData")
    public AjaxResult indexData(){
        return AjaxResult.success(tbQualifiedCertInfoService.getAppIndexData());
    }

    /**
     * 根据多个合格证ID获取合格证信息
     * @param ids 合格证ID，多个以英文逗号隔开
     */
    @GetMapping("printInfo")
    public AjaxResult printInfo(String ids){
        return AjaxResult.success(tbQualifiedCertInfoService.getPrintInfo(ids));
    }


}
